<?php
/**
* @package		JBS
* @license		GNU/GPL, see LICENSE.php
*/

jimport('joomla.application.component.view');

/**
 * HTML View class for the JBS Component
 *
 * @package		JBS
 */
class JBSViewUsers extends JView {
	function display($tpl = null) {
		$task = JRequest :: getVar('task');

		switch ($task) {
			case 'edit':
				//get all userroles from Request which is retrived from User Controller Edit function
				$roles = JRequest :: getVar('roles');
				$users = & $this->get('Data');
				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText :: _('USERS') . ': <small><small>[ ' . JText :: _('Edit') . ' ]</small></small>', 'jbschedule');
				JToolBarHelper :: save();
				// for existing items the button is renamed `close`
				JToolBarHelper :: cancel('cancel', 'Close');
				$this->assignRef('users', $users);

				//Chuyen userroles cho Template
				$this->assignRef('roles', $roles);
				break;

			case 'add':
				//get all userroles from Request which is retrived from User Controller Edit function
				$roles = JRequest :: getVar('roles');
				//get all joomla users from DB
				$system_users = JRequest :: getVar('system_users');
				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText :: _('USERS') . ': <small><small>[ ' . JText :: _('New') . ' ]</small></small>', 'jbschedule');
				JToolBarHelper :: save();
				// for existing items the button is renamed `close`
				JToolBarHelper :: cancel('cancel', 'Close');
				//Chuyen userroles cho Template
				$this->assignRef('roles', $roles);
				//Chuyen system_users cho Template
				$this->assignRef('system_users', $system_users);
				break;

			default:
				global $mainframe, $option;
				//initialise variables
				$db			= & JFactory::getDBO();
				
				//get vars
				$filter_order		= $mainframe->getUserStateFromRequest( $option.'.users.filter_order', 'filter_order', 	'title', 'cmd' );				
				$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'.users.filter_order_Dir', 'filter_order_Dir', '', 'word' );
				$search 			= $mainframe->getUserStateFromRequest( $option.'.users.search', 'search', '', 'string' );
				$search 			= $db->getEscaped( trim(JString::strtolower( $search ) ) );
				$template			= $mainframe->getTemplate();
				
				JToolBarHelper :: title(JText::_('PROJECT NAME').' - '.JText :: _('USERS MANAGER'), 'jbschedule');
				JToolBarHelper :: deleteList(JText :: _('ARE YOU SURE')); //param: 1: message 2: task to do 3: Label of the button
				JToolBarHelper :: editListX();
				JToolBarHelper::addNewX();

				// Get data from the model
				$items      = & $this->get( 'DataList');
				//$total    = & $this->get( 'Total');
				$pageNav 	= & $this->get( 'Pagination' );				
				
				// table ordering
				$lists['order_Dir'] = $filter_order_Dir;
				$lists['order'] = $filter_order;
		
				// search filter
				$lists['search']= $search;

				$this->assignRef('items'		, $items);				
				$this->assignRef('lists'      	, $lists);
				$this->assignRef('pageNav' 		, $pageNav);
				$this->assignRef('template'		, $template);

				break;
		}

		parent :: display($tpl);
	}

}
?>
